package org.example.repository;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

@Getter
@Setter
@Accessors(fluent = true)
public class Schema {

    private String name;
    private Class<? extends Entity<?>> entityClass;
    @Getter(AccessLevel.NONE)
    @Setter(AccessLevel.NONE)
    private final LinkedHashMap<String, Property> properties = new LinkedHashMap<>();

    public Schema(String name, Class<? extends Entity<?>> entityClass) {
        this.name = name;
        this.entityClass = entityClass;
    }

    public List<Property> properties() {
        return new ArrayList<>(properties.values());
    }

    public Schema properties(List<Property> properties) {
        this.properties.clear();
        for (Property property : properties) {
            this.properties.put(property.name(), property);
        }
        return this;
    }

    public Property property(String name) {
        return properties.get(name);
    }


    public Schema property(String name, String type) {
        Property property = new Property(name, type);
        return property(property);
    }

    public Schema property(Property property) {
        this.properties.put(property.name(), property);
        return this;
    }
}
